package com.hulk.common;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

/**
 * 模拟http请求
 * @author CUIJIAJUN
 * @date   2016年11月29日
 * 
 */
public class HttpSend {
	private static CloseableHttpClient httpClient = HttpClients.createDefault();
//    private HttpPost httpPost;
    private static String host = "http://192.168.1.82:8080";
	
//	public void init() {
//	    httpClient = HttpClients.createDefault();
//	}
	public static void main(String[] args) throws Exception {
		// 参数： appType,  merchantId, serviceType, pageNo
		HttpPost httpPost = new HttpPost(host+"/common/saveResponsivity");
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();
        Long time = System.currentTimeMillis();
        parameters.add(new BasicNameValuePair("time", time+""));
        parameters.add(new BasicNameValuePair("responsivity", "123"));
        parameters.add(new BasicNameValuePair("city", "456"));
        HttpEntity entity = new UrlEncodedFormEntity(parameters, "UTF8");
        httpPost.setEntity(entity);
        CloseableHttpResponse resp = httpClient.execute(httpPost);
        System.out.println(EntityUtils.toString(resp.getEntity(), "UTF8"));
        resp.close();
        httpClient.close();
	}
}

